package UI

import (
	. "SGEngine"
	//"fmt"
)

type UIRect struct {
	Top    int
	Bottom int
	Left   int
	Right  int
}

type UINode struct {
	Node
	AnchorPoint Vec2 //锚点  左下为  (0,0)
}

func NewUINode() *UINode {
	RUINode := new(UINode)
	UIT := new(UITransfrom)
	UIT.Mnode = RUINode
	RUINode.ITransfrom = UIT
	UIT.SetIsSizeScale(false)
	UIT.SetSize(1, 1, 1)
	RUINode.SetMat(Mat4Identity.Clone())
	RUINode.MGetRect = uinode_GetRect
	RUINode.Enable = true
	RUINode.AnchorPoint = Vec2{0, 1}
	return RUINode
}

func uinode_GetRect(node INode, Scale Vec3, Pos Vec3) *Rect {

	r := new(Rect)
	T := node.GetTransfrom()
	SX, SY := Scale.X, Scale.Y
	PX, PY := Pos.X, Pos.Y
	Half_X := SX * 0.5 * T.Size().X
	Half_Y := SY * 0.5 * T.Size().Y
	uinode := T.GetT().Mnode.(*UINode)

	r.MinX = PX - (Half_X * 2 * uinode.AnchorPoint.X)
	r.MaxX = PX + (Half_X * 2 * (1 - uinode.AnchorPoint.X))
	r.MinY = PY - (Half_Y * 2 * uinode.AnchorPoint.Y)
	r.MaxY = PY + (Half_Y * 2 * (1 - uinode.AnchorPoint.Y))
	return r
}
